/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Calendar;
import java.util.concurrent.TimeUnit;

/**
 * <p>Project: javaseapp - Thread6
 * <p>Powered by webrx On 2021-08-24 15:28:25
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Thread6 {
    public static void main(String[] args) {
        new Thread(() -> {
            long start = System.currentTimeMillis();
            var c = Calendar.getInstance();
            c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 1);
            c.set(Calendar.DAY_OF_MONTH, 0);
            c.set(Calendar.HOUR_OF_DAY, 2);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            long end = c.getTimeInMillis();
            while (true) {
                System.out.println("ok");
                try {
                    TimeUnit.MILLISECONDS.sleep(end - start);
                    System.out.println("执行数据库备份命令！！！");
                    start = System.currentTimeMillis();
                    var cc = Calendar.getInstance();
                    cc.set(Calendar.MONTH, cc.get(Calendar.MONTH) + 1);
                    cc.set(Calendar.DAY_OF_MONTH, 0);
                    cc.set(Calendar.HOUR_OF_DAY, 2);
                    cc.set(Calendar.MINUTE, 0);
                    cc.set(Calendar.SECOND, 0);
                    end = cc.getTimeInMillis();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
